package com.sunlg.smarthome.ui.personal;

import android.content.Context;
import android.content.DialogInterface;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AlertDialog;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;

import com.sunlg.smarthome.R;

/**
 * Created by sunlg on 2017/5/30.
 */

public class UpdatePwdDialog {
    private Context context;
    private AlertDialog.Builder builder;
    private AlertDialog dialog;
    private View view;
    private TextInputEditText textInputEditText1;
    private TextInputEditText textInputEditText2;

    private OnEditTextInputListener editTextInputListener;

    public UpdatePwdDialog(Context context) {
        this.context = context;

    }

    public void show(){
        builder = new AlertDialog.Builder(context);
        view = LayoutInflater.from(context).inflate(R.layout.dialog_with_edittext2, null);
        textInputEditText1 = (TextInputEditText)view.findViewById(R.id.et_1);
        textInputEditText2 = (TextInputEditText)view.findViewById(R.id.et_2);
        textInputEditText1.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
        textInputEditText2.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
        textInputEditText1.setHint("新密码");
        textInputEditText2.setHint("确认密码");

        if(view != null) {
            builder.setView(view);
        }

        builder.setTitle("修改密码");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                editTextInputListener.onEditTextInput(textInputEditText1.getText().toString(),
                        textInputEditText1.getText().toString());
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog = builder.create();

        dialog.show();
    }

    public void hide(){
        if(dialog != null){
            dialog.dismiss();
        }
    }

    public boolean isShowing(){
        return dialog.isShowing();
    }

    public interface OnEditTextInputListener{
        void onEditTextInput(String inputText1, String inputText2);
    }

    public void setOnEditTextInputListener(OnEditTextInputListener listener){
        editTextInputListener = listener;
    }
}
